package com.heima.minio.test;

import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import org.junit.Test;

import java.io.FileInputStream;

public class MinioTest2 {
    //WlgO5b6spBJofsxAUn43
    //mu8p13LlrIuXZwOoLZCNiZXI6Nr4jS2FjHTafO2Y
    private String accessKey = "WlgO5b6spBJofsxAUn43";
    private String secretKey = "mu8p13LlrIuXZwOoLZCNiZXI6Nr4jS2FjHTafO2Y";
    @Test
    public void test1(){
        FileInputStream fileInputStream = null;
        try {

            fileInputStream =  new FileInputStream("E:\\aa\\plugins\\js\\axios.min.js");;

            //1.创建minio链接客户端
            MinioClient minioClient = MinioClient.builder().credentials(accessKey, secretKey).endpoint("http://192.168.189.135:9000").build();
            //2.上传
            PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                    .object("plugins/js/axios.min.js")//文件名
                    .contentType("text/javascript")//文件类型
                    .bucket("leadnews")//桶名词  与minio创建的名词一致
                    .stream(fileInputStream, fileInputStream.available(), -1) //文件流
                    .build();
            minioClient.putObject(putObjectArgs);

            //System.out.println("http://192.168.189.135:9000/leadnew/ak47.jpg");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    ///2021/4/20210418/4a498d9cf3614570ac0cb2da3e51c164.jpg
    @Test
    public void test2(){
        FileInputStream fileInputStream = null;
        try {

            fileInputStream =  new FileInputStream("E:\\aa\\image\\1.jpg");;

            //1.创建minio链接客户端
            MinioClient minioClient = MinioClient.builder().credentials(accessKey, secretKey).endpoint("http://192.168.189.135:9000").build();
            //2.上传
            PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                    .object("2021/4/20210418/4a498d9cf3614570ac0cb2da3e51c164.jpg")//文件名
                    .contentType("image/jpeg")//文件类型
                    .bucket("leadnews")//桶名词  与minio创建的名词一致
                    .stream(fileInputStream, fileInputStream.available(), -1) //文件流
                    .build();
            minioClient.putObject(putObjectArgs);

            //System.out.println("http://192.168.189.135:9000/leadnew/ak47.jpg");

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
